package com.dykj.dati.config;



import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dykj.dati.model.t.*;
import com.dykj.dati.model.user.HUser;
import com.dykj.dati.service.t.ITJiaojuanService;
import com.dykj.dati.service.t.ITKuDaService;
import com.dykj.dati.service.t.ITKuTitleService;
import com.dykj.dati.service.t.ITKuZongLinshiService;
import com.dykj.dati.service.user.IHUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.AliasFor;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;



import static com.dykj.dati.controller.h5.JiaoJuanController.*;
import static com.dykj.dati.controller.h5.KSController.*;


@Component
@Order(value = 2)
public class CommandLineRunnerImpl implements CommandLineRunner {
    @Autowired
    private ITKuZongLinshiService itKuZongLinshiService;
    @Autowired
    private ITKuTitleService itKuTitleService;
    @Autowired
    private RedisCache redisCache;
    @Autowired
    private ITKuDaService itKuDaService;
    @Autowired
    private IHUserService ihUserService;
    @Autowired
    private ITJiaojuanService itJiaojuanService;
    @Override
    public void run(String... args) throws Exception {
        initSystem();
    }
    public void initSystem(){
        List<TKuTitle> tKuTitleList=itKuTitleService.list();
        for(TKuTitle tKuTitle:tKuTitleList){
            QueryWrapper queryWrapper=new QueryWrapper();
            queryWrapper.eq("t_id",tKuTitle.getId());
            queryWrapper.orderByAsc("k");
            List<TKuDa> tKuDaList=itKuDaService.list(queryWrapper);
            TiZong tiZong=new TiZong();
            tiZong.setTid(tKuTitle.getId());
            tiZong.setTitle(tKuTitle.getTitle());
            tiZong.setDa(tKuDaList);
            tizongList.add(tiZong);
            tizongMap.put(tKuTitle.getId(),tKuTitle.getTitle());
            tkSuccessMap.put(tKuTitle.getId(),tKuTitle.getZq());

            for(TKuDa tKuDa:tKuDaList){
                titleXuanxiang.put(tKuTitle.getId()+"_"+tKuDa.getK(),tKuDa.getDa());
            }

        }
    }
    public void shuati(){
        List<TKuZongLinshi> tKuZongLinshiList=itKuZongLinshiService.list();
        List<TKuTitle> tKuTitleList=new ArrayList<>();
        List<TKuDa> tKuDaList=new ArrayList<>();
        for(TKuZongLinshi tKuZongLinshi:tKuZongLinshiList){
            String tid=IdUtil.simpleUUID();
            TKuTitle tKuTitle=new TKuTitle();
            tKuTitle.setId(tid);
            tKuTitle.setCreateTime(DateUtil.date());
            tKuTitle.setTitle(tKuZongLinshi.getTitle());
            tKuTitle.setZq(tKuZongLinshi.getZq());
            tKuTitleList.add(tKuTitle);



            TKuDa tKuDa=new TKuDa();
            tKuDa.setId(IdUtil.simpleUUID());
            tKuDa.setCreateTime(DateUtil.date());
            tKuDa.setTId(tid);
            tKuDa.setK("A");
            tKuDa.setDa(tKuZongLinshi.getXxa());
            tKuDaList.add(tKuDa);



            TKuDa tKuDab=new TKuDa();
            tKuDab.setId(IdUtil.simpleUUID());
            tKuDab.setCreateTime(DateUtil.date());
            tKuDab.setTId(tid);
            tKuDab.setDa(tKuZongLinshi.getXxb());
            tKuDab.setK("B");
            tKuDaList.add(tKuDab);




            TKuDa tKuDac=new TKuDa();
            tKuDac.setId(IdUtil.simpleUUID());
            tKuDac.setCreateTime(DateUtil.date());
            tKuDac.setTId(tid);
            tKuDac.setDa(tKuZongLinshi.getXxc());
            tKuDac.setK("C");
            tKuDaList.add(tKuDac);
        }
        itKuTitleService.saveBatch(tKuTitleList);
        itKuDaService.saveBatch(tKuDaList);
    }
}
